package ar.fi.uba.fallas2.business;

import java.sql.PreparedStatement;
import ar.fi.uba.fallas2.data.DataException;
import ar.fi.uba.fallas2.data.Database;

public class Answer extends BusinessObject {
	private GuessObject object;
	private Question question;
	private AnswerKind kind;
	private int weight;
	private static final String insertStatementString = "INSERT INTO answer(fk_id_object, fk_id_question, fk_id_kind, weight) VALUES (?,?,?,?)";	
	
	public Answer() {
		super("answer");
	}
	
	public Answer(int id) {
		super("answer", id);
	}
	
	protected void insert() throws DataException {
		PreparedStatement insertStatement = null;
		try {
			insertStatement = Database.getInstance().prepareStatement(insertStatementString);
			insertStatement.setInt(1, this.getObject().getId());
			insertStatement.setInt(2, this.getQuestion().getId());
			insertStatement.setInt(3, this.getKind().getId());
			insertStatement.setInt(4, this.getWeight());
			insertStatement.execute();
		} catch (Exception e) {
			throw new DataException(e);
		}
	}
	
	protected void update() throws DataException {
		throw new DataException(new Exception("No se puede actualizar una entidad ANSWER"));
	}
	
	public void delete() throws DataException {
		throw new DataException(new Exception("No se puede eliminar una entidad ANSWER"));
	}
	
	public static void deleteAll() throws DataException {
		String findStatementString = "DELETE FROM answer";
		PreparedStatement findStatement = null;
		try {
			findStatement = Database.getInstance().prepareStatement(findStatementString);
			findStatement.execute();
		} catch (Exception e) {
			throw new DataException(e);
		}
	}

	public void setObject(GuessObject object) {
		this.object = object;
	}

	public GuessObject getObject() {
		return object;
	}

	public void setQuestion(Question question) {
		this.question = question;
	}

	public Question getQuestion() {
		return question;
	}

	public void setKind(AnswerKind kind) {
		this.kind = kind;
	}

	public AnswerKind getKind() {
		return kind;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public int getWeight() {
		return weight;
	}
}
